package com.woniuxy.classteacher.mqreceiver;

import com.rabbitmq.client.Channel;
import com.woniuxy.classteacher.uitility.EmailUtil;
import com.woniuxy.commons.entity.StudentInfo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Auther: 牟强
 * @Date: 2020/7/18/018 14:34
 * @Description: 邮件发送队列
 */
@Component
public class EmailMQ {
    @RabbitListener(queues = "email")
    public void received(StudentInfo student, Channel channel, Message message) throws IOException {
        //System.out.println("邮箱收到" + student);
        //发送邮件
//        EmailUtil.sendMail(student.getEmail());

        //测试暂时发送到测试的邮箱
        EmailUtil.sendMail("727344015@qq.com");
        //System.out.println("发送邮件完成");
        //手动确认消息，移除消息队列
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
